package com.eamois.ui.manual;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Set;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import com.eamois.action.manual.CatalogAction;
import com.eamois.action.manual.DiagramAction;
import com.eamois.action.manual.ProcessAction;
import com.eamois.action.manual.ProcessEntityColsAction;
import com.eamois.action.manual.ProcessEntityColsContextAction;
import com.eamois.action.manual.StoppageAndProcessStructureAction;
import com.eamois.action.manual.WorkStepAction;
import com.eamois.action.manual.WorkStepColsAction;
import com.eamois.action.manual.WorkStepColsContextAction;
import com.eamois.action.sys.DifferentialMeaTemplateAction;
import com.eamois.action.sys.MeaContentAction;
import com.eamois.action.sys.MeaPolygonAction;
import com.eamois.domain.manual.Catalog;
import com.eamois.domain.manual.Diagram;
import com.eamois.domain.manual.EnsipBom;
import com.eamois.domain.manual.ProcessEntity;
import com.eamois.domain.manual.ProcessEntityCols;
import com.eamois.domain.manual.ProcessEntityColsContext;
import com.eamois.domain.manual.Stoppage;
import com.eamois.domain.manual.StoppageAndProcessStructure;
import com.eamois.domain.manual.Technology;
import com.eamois.domain.manual.WorkStep;
import com.eamois.domain.manual.WorkStepCols;
import com.eamois.domain.manual.WorkStepColsContext;
import com.eamois.domain.sys.Device;
import com.eamois.domain.sys.DifferentialMeaTemplate;
import com.eamois.domain.sys.Equipment;
import com.eamois.domain.sys.Instrument;
import com.eamois.domain.sys.MeaContent;
import com.eamois.domain.sys.MeaPolygon;
import com.eamois.domain.sys.SubMaterial;
import com.eamois.pdmutil.pdmui.PnlEamoisBrowser;
import com.eamois.ui.sys.DlgCodeSetting;
import com.eamois.ui.util.PolygonUtil;
import com.eamois.ui.util.UIToolkit;
import com.eamois.util.Constants;
import com.eamois.util.DeviceSort;
import com.eamois.util.EquipmentSort;
import com.eamois.util.InstrumentSort;
import com.eamois.util.PartSort;
import com.eamois.util.PolygonSort;
import com.eamois.util.SubMaterialSort;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.rtf.RtfWriter2;
import com.lowagie.text.rtf.field.RtfPageNumber;
import com.lowagie.text.rtf.headerfooter.RtfHeaderFooter;
import com.mit.control.MitMenu;
import com.mit.control.MitMenuItem;
import com.mit.plm.client.integration.Browse;
import com.mit.plm.client.main.Message;
import com.mit.plm.client.publicClass.MitPDMPanel;
import com.mit.plm.sql.documentManage.SqlMix;
import com.mit.plm.view.documentmanage.ViewDocument;
import com.test.ColorFrame;

public class FrmManual extends MitPDMPanel {

	private MitPDMPanel contentPane;
	private MitPDMPanel pnlMenu;
	// private MitPDMMainMenuBar menuBar;
	private JMenuBar menuBar;
	private MitMenu menu_file;
	private MitMenu menu_edit;
	private MitMenu menu_view;
	private MitMenu menu_tool;
	private MitMenu menu_help;
	private MitMenuItem menuItem_save;
	private MitMenuItem menuItem_open;
	private MitMenuItem menuItem_about;
	private MitMenuItem menuItem_print;
	private MitMenuItem menuItem_export;
	private MitMenuItem menuItem_codeSetting;
	private MitMenuItem menuItem_codeMgr;
	private static Connection connection;
	public static Icon redIcon = new ImageIcon(ColorFrame.class.getResource("icons/red.jpg"));
	public static Icon blueIcon = new ImageIcon(ColorFrame.class.getResource("icons/blue.jpg"));
	public static Icon greenIcon = new ImageIcon(ColorFrame.class.getResource("icons/green.jpg"));
	
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

		} catch (Exception e) {
			// TODO: handle exception
		}
		EventQueue.invokeLater(new Runnable() {
			@Override
			public void run() {
				try {
					FrmManual frame = new FrmManual();
					UIToolkit.center(frame);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FrmManual() {
		initGUI();
	}

	private void initGUI() {
//		CentreInWindows.fullscreen(this);
//		setTitle("交互式电子技术手册");
		setBounds(100, 100, 1100, 700);
		contentPane = new MitPDMPanel();
		this.setBorder(new EmptyBorder(5, 5, 5, 5));
		this.setLayout(new BorderLayout(0, 0));
//		setContentPane(contentPane);
//        this.add(contentPane);
		PnlManual pnlManual = new PnlManual();
		pnlManual.setBorder(new EmptyBorder(-5, 0, -5, 0));
		this.add(getPnlMenu(), BorderLayout.NORTH);
		this.add(pnlManual, BorderLayout.CENTER);
		this.add(getPnlColor(), BorderLayout.SOUTH);
		this.addToolBar(pnlManual.commonBar);
//		this.addToolBar(pnlManual.technologyBar);
//		this.addToolBar(pnlManual.techOrderBar);
//		this.addToolBar(pnlManual.techStepBar);
		
	}
	private JPanel getPnlColor() {
		JPanel panel_1 = new JPanel();
//		BorderLayout.WEST
		panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));		
		JLabel label = new JLabel("正在审签:");
		panel_1.add(label);		
		JLabel label_1 = new JLabel();
		label_1.setIcon(greenIcon);
		panel_1.add(label_1);
		
		JLabel label1 = new JLabel("审签完成:");
		panel_1.add(label1);		
		JLabel label_11 = new JLabel();
		label_11.setIcon(blueIcon);
		panel_1.add(label_11);
		
		JLabel label2 = new JLabel("审签打回:");
		panel_1.add(label2);		
		JLabel label_12 = new JLabel();
		label_12.setIcon(redIcon);
		panel_1.add(label_12);
		
		
		
		return panel_1;
		
	}
	
	
	
	
	
	
	private MitPDMPanel getPnlMenu() {
		if (pnlMenu == null) {
			pnlMenu = new MitPDMPanel();
			pnlMenu.setBorder(new EmptyBorder(-5, 0, -5, 0));
			pnlMenu.setAlignmentX(0.0f);
			pnlMenu.setAlignmentY(0.0f);
			FlowLayout flowLayout = (FlowLayout) pnlMenu.getLayout();
			flowLayout.setVgap(0);
			flowLayout.setHgap(0);
			flowLayout.setAlignment(FlowLayout.LEFT);

			menuBar = new JMenuBar();
			menuBar.setFont(new Font("Segoe UI", Font.PLAIN, 12));
			menuBar.setBorderPainted(false);
			pnlMenu.add(menuBar);

			menu_file = new MitMenu("文件(F)");
//			menuBar.add(menu_file);
			this.addMenu(menu_file);
			menu_file.setMnemonic('F');

			menuItem_open = new MitMenuItem("打开");
			menu_file.add(menuItem_open);

			menuItem_save = new MitMenuItem("保存");
			menu_file.add(menuItem_save);

			menu_edit = new MitMenu("编辑(E)");
			menu_edit.setMnemonic('E');
//			menuBar.add(menu_edit);
			this.addMenu(menu_edit);
			menu_view = new MitMenu("查看(V)");
			menu_view.setMnemonic('V');
//			menuBar.add(menu_view);
			this.addMenu(menu_view);
			menu_tool = new MitMenu("工具(T)");
			menu_tool.setMnemonic('T');
//			menuBar.add(menu_tool);
			this.addMenu(menu_tool);
			menuItem_export = new MitMenuItem("导出");
			menuItem_export.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					setCursor(new Cursor(Cursor.WAIT_CURSOR));
					DlgSelectTechnology dlg = new DlgSelectTechnology();
					UIToolkit.center(dlg);
					dlg.setModal(true);
					dlg.setVisible(true);
					setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
					if (dlg.isCommit()) {
//						Technology technology = dlg.getTechnology();
						// 导出选择的工艺到PDF
//						Set<Catalog> list = technology.getCatalogs();
//						ArrayList<Catalog> catalogs = new ArrayList<Catalog>();
//						for (Catalog catalog : list) {
//							catalogs.add(catalog);
//						}
						// 排序
//						CatalogSort sort = new CatalogSort();
//						Collections.sort(catalogs, sort);
						String path = dlg.getPath();
//						createPDF(path, technology, catalogs);
//						CatalogAction action = new CatalogAction();
//						ArrayList<Catalog> catalogs= (ArrayList<Catalog>)action.findAllCatalog();
						Collection<Technology> technologies = dlg.getTechnologies();
						//针对不同的工艺存在不同的工艺目录
//						ArrayList<Catalog> catalogs= (ArrayList<Catalog>)action.findAllCatalogByTech(technology);
//						createWord(path, technology, catalogs);
						createWord(path, technologies);
					}
				}
			});
			//测试
//			menuItem_open.addActionListener(new ActionListener() {
//				@Override
//				public void actionPerformed(ActionEvent e) {
//					PnlTechnologyDetail dlg = new PnlTechnologyDetail("", "");
//					UIToolkit.center(dlg);
//					dlg.setModal(true);
//					dlg.setVisible(true);
//				}
//			});
			menu_tool.add(menuItem_export);
			menuItem_codeSetting = new MitMenuItem("编码设置");
			menuItem_codeSetting.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					setCursor(new Cursor(Cursor.WAIT_CURSOR));
					DlgCodeSetting dlg = new DlgCodeSetting();
					UIToolkit.center(dlg);
					dlg.setModal(true);
					dlg.setVisible(true);
					setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
					if (dlg.isCommit()) {
//						Technology technology = dlg.getTechnology();
//						String path = dlg.getPath();
//						createWord(path, technology, null);
					}
				}
			});
			menu_tool.add(menuItem_codeSetting);
			
			
			menuItem_codeMgr = new MitMenuItem("编码管理");
			menuItem_codeMgr.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					setCursor(new Cursor(Cursor.WAIT_CURSOR));
					DlgCodeManager dlg = new DlgCodeManager();
					UIToolkit.center(dlg);
					dlg.setModal(true);
					dlg.setVisible(true);
					setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
					if (dlg.isCommit()) {
//						Technology technology = dlg.getTechnology();
//						String path = dlg.getPath();
//						createWord(path, technology, null);
					}
				}
			});
			menu_tool.add(menuItem_codeMgr);

			// menuItem_print = new MitMenuItem("打印");
			// menu_tool.add(menuItem_print);

			menu_help = new MitMenu("帮助(H)");
//			menuBar.add(menu_help);

			menuItem_about = new MitMenuItem();
			menuItem_about.setText("关于");
//			menu_help.add(menuItem_about);
		}
		return pnlMenu;
	}

	/*// DPF导出方法
	@SuppressWarnings("unchecked")
	private static void createPDF(String path, Technology technology,
			ArrayList<Catalog> catalogs) {

		Document document = new Document(PageSize.A4, 20, 20, 20, 20);
		try {
			// 输出为文件
			PdfWriter.getInstance(document, new FileOutputStream(path));
			// 打开文档
			document.open();
			BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",
					"UniGB-UCS2-H", false);
			com.lowagie.text.Font fontChinese = new com.lowagie.text.Font(
					bfChinese, 14, Font.BOLD);
			com.lowagie.text.Font fontChinese2 = new com.lowagie.text.Font(
					bfChinese);
			fontChinese2.setSize(10f);

			PdfPTable table1 = getTable();

			// 在pdf文件中写入文字
			// 标题
			PdfPCell cell0 = new PdfPCell(new Paragraph("中国人民解放军第五七一九工厂",
					fontChinese));
			cell0.setColspan(6);
			cell0.setFixedHeight(20);
			cell0.setPadding(0);
			cell0.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell0.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell0.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell0);

			// 标题
//			PdfPCell cell1 = new PdfPCell(new Paragraph("航空发动机"+ technology.getType() + "工艺规程", fontChinese));
			PdfPCell cell1 = new PdfPCell(new Paragraph("航空发动机"+"" + "工艺规程", fontChinese));
			cell1.setColspan(6);
			cell1.setFixedHeight(20);
			cell1.setPadding(0);
			cell1.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell1.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell1.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell1);

			// 工艺编码
			PdfPCell cell2 = new PdfPCell(new Paragraph(technology.getCode(),
					fontChinese2));
			cell2.setColspan(6);
			cell2.setFixedHeight(20);
			cell2.setPadding(0);
			cell2.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell2.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell2.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell2);

			// 分隔
			PdfPCell cell3 = new PdfPCell(
					new Paragraph(
							"___________________________________________________________________",
							fontChinese));
			cell3.setColspan(6);
			cell3.setFixedHeight(20);
			cell3.setPadding(0);
			cell3.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell3.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell3.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell3);

			PdfPCell cell4 = new PdfPCell(new Paragraph(technology.getName(),
					fontChinese));
			cell4.setColspan(6);
			cell4.setFixedHeight(300);
			cell4.setPadding(0);
			cell4.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell4.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell4.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell4);

			PdfPCell cell9 = new PdfPCell(new Paragraph("", fontChinese));
			cell9.setColspan(6);
			cell9.setFixedHeight(300);
			cell9.setPadding(0);
			cell9.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell9.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell9.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell9);

			// 分隔
			PdfPCell cell8 = new PdfPCell(
					new Paragraph(
							"___________________________________________________________________",
							fontChinese));
			cell8.setColspan(6);
			cell8.setFixedHeight(20);
			cell8.setPadding(0);
			cell8.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell8.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell8.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell8);

			PdfPCell cell5 = new PdfPCell(new Paragraph("中国人民解放军第五七一九工厂",
					fontChinese2));
			cell5.setColspan(6);
			cell5.setFixedHeight(20);
			cell5.setPadding(0);
			cell5.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell5.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell5.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell5);

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
			Date date = new Date();
			String day = sdf.format(date);
			PdfPCell cell6 = new PdfPCell(new Paragraph(day, fontChinese2));
			cell6.setColspan(6);
			cell6.setFixedHeight(20);
			cell6.setPadding(0);
			cell6.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			cell6.setVerticalAlignment(Element.ALIGN_BOTTOM);
			cell6.setBorder(Rectangle.NO_BORDER);
			table1.addCell(cell6);

			document.add(table1);
			document.newPage();

			PdfPTable table2 = getTable();

			PdfPCell mulu = new PdfPCell(new Paragraph("目录", fontChinese));
			mulu.setColspan(6);
			mulu.setFixedHeight(20);
			mulu.setPadding(0);
			mulu.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容水平居中显示
			mulu.setVerticalAlignment(Element.ALIGN_BOTTOM);
			mulu.setBorder(Rectangle.NO_BORDER);
			table2.addCell(mulu);

			int index = 1;
			for (Catalog catalog : catalogs) {
				String con = index + " " + catalog.getName();
				PdfPCell cell = new PdfPCell(new Paragraph(con, fontChinese));
				cell.setColspan(6);
				cell.setFixedHeight(20);
				cell.setPadding(0);
				cell.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
				cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
				cell.setBorder(Rectangle.NO_BORDER);
				table2.addCell(cell);
				// 工序内容下工步
				if (catalog.getType().equals(Constants.CATALOGTYPE_GXNR)) {
					ProcessAction action = new ProcessAction();
					Collection<ProcessEntity> pros = action.findProcessByTechnology(technology);
					int num = 1;
					for (ProcessEntity processEntity : pros) {
						PdfPCell cellProcess = new PdfPCell(new Paragraph(index
								+ "." + num + " " + processEntity.getName(),
								fontChinese));
						cellProcess.setColspan(6);
						cellProcess.setFixedHeight(20);
						cellProcess.setPadding(0);
						cellProcess.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
						cellProcess.setVerticalAlignment(Element.ALIGN_BOTTOM);
						cellProcess.setBorder(Rectangle.NO_BORDER);
						table2.addCell(cellProcess);
						num++;
					}
				}
				index++;
			}
			document.add(table2);
			document.newPage();

			PdfPTable table3 = getTable();
			List<Image> images = new ArrayList<Image>();
			// 循环添加每个工艺类型内容
			int index2 = 1;
			for (Catalog catalog : catalogs) {
				// 总则
				if (catalog.getType().equals(Constants.CATALOGTYPE_ZZ)) {
					GengralRulesAction action = new GengralRulesAction();
					GengralRules gengralRules = action
							.findGengralRulesByCatalogAndTechnology(catalog,
									technology);
					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_ZZ, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setPadding(0);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_BOTTOM);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);

					// 内容
					Paragraph paragraph = new Paragraph(
							gengralRules == null ? ""
									: gengralRules.getContent(), fontChinese2);
					PdfPCell cell_message = new PdfPCell(paragraph);
					cell_message.setColspan(6);
					cell_message.setLeading(0, 1.5f);
					cell_message.setPadding(0);
					// cell_message.setPaddingLeft(10);
					cell_message.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_message.setVerticalAlignment(Element.ALIGN_BOTTOM);
					cell_message.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_message);

				}// 工序内容
				else if (catalog.getType().equals(Constants.CATALOGTYPE_GXNR)) {
					ProcessAction action = new ProcessAction();
					Collection<ProcessEntity> procs = action.findProcessByTechnology(technology);
					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_GXNR, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setPadding(0);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_BOTTOM);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);
					// 内容
					int i = 1;
					for (ProcessEntity process : procs) {
						PdfPCell cell_message = new PdfPCell(new Paragraph(
								index2 + "." + i + "、" + process.getName(),
								fontChinese2));
						cell_message.setColspan(6);
						cell_message.setPadding(0);
						// cell_message.setFixedHeight(15);
						cell_message.setLeading(0, 1.5f);
						cell_message.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
						cell_message.setVerticalAlignment(Element.ALIGN_BOTTOM);
						cell_message.setBorder(Rectangle.NO_BORDER);
						table3.addCell(cell_message);
					
						//工序表格相关内容
						ProcessEntityColsAction colsAction = new ProcessEntityColsAction();
						ProcessEntityColsContextAction colsContextAction = new ProcessEntityColsContextAction();
						// 列名
						List<ProcessEntityCols> colsList = (ArrayList<ProcessEntityCols>) colsAction
								.findEnsipEntityCols(process);
						// 空白部分
						PdfPCell blank = new PdfPCell(new Paragraph("",
								fontChinese2));
						blank.setFixedHeight(10);
						blank.setBorder(0);
						blank.setColspan(6);
						table3.addCell(blank);
						// 工序表格列
						if (colsList != null && colsList.size() > 0) {
							PdfPTable table = new PdfPTable(colsList.size());
							for (int j = 0; j < colsList.size(); j++) {
								PdfPCell title = new PdfPCell(new Paragraph(
										colsList.get(j) + "", fontChinese2));
								// title.setFixedHeight(20);
								title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
								title.setVerticalAlignment(Element.ALIGN_MIDDLE);
								// title.setLeading(0,1.5f);
								table.addCell(title);

							}

							PdfPCell pcell = new PdfPCell(table);
							pcell.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							pcell.setVerticalAlignment(Element.ALIGN_MIDDLE);
							pcell.setColspan(6);
							table3.addCell(pcell);
						}
						// 工序表格内容
						List<ProcessEntityColsContext> colsContext = new ArrayList<ProcessEntityColsContext>();
						List<List<ProcessEntityColsContext>> allColsContext = new ArrayList<List<ProcessEntityColsContext>>();
						for (ProcessEntityCols processEntityCols : colsList) {
							colsContext = (ArrayList<ProcessEntityColsContext>) colsContextAction
									.findEnsipEntityColsContext(processEntityCols);
							allColsContext.add(colsContext);
						}
						if (colsContext != null && colsContext.size() > 0) {
							PdfPTable table = new PdfPTable(colsList.size());
							for (int m = 0; m < colsContext.size(); m++) {
								for (int n = 0; n < allColsContext.size(); n++) {
									PdfPCell cell = new PdfPCell();

									cell = new PdfPCell(new Paragraph(
											allColsContext.get(n).get(m)
													.toString(), fontChinese2));

									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
									table.addCell(cell);
								}

							}
							PdfPCell cell = new PdfPCell(table);
							cell.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
							cell.setColspan(6);
							table3.addCell(cell);
						}
						
						if (process.getRemark() != null
								&& !process.getRemark().equals("")) {
							Paragraph paragraph = new Paragraph("注:"
									+ process.getRemark(), fontChinese2);
							paragraph.setLeading(10f);
							PdfPCell cell_remark = new PdfPCell(paragraph);
							cell_remark.setColspan(6);
							cell_remark.setPadding(0);
							cell_remark.setPaddingLeft(10);
							// cell_remark.setFixedHeight(15);
							cell_remark.setLeading(0, 1.5f);
							cell_remark
									.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
							cell_remark
									.setVerticalAlignment(Element.ALIGN_BOTTOM);
							cell_remark.setBorder(Rectangle.NO_BORDER);
							table3.addCell(cell_remark);
						}
						i++;
						WorkStepAction action2 = new WorkStepAction();
						Collection<WorkStep> steps = action2
								.findStepByProcess(process);
						int j = 1;
						for (WorkStep step : steps) {
							StringBuffer message = new StringBuffer();
							if (step.getDiagrams().size() != 0) {
								for (Diagram diagram : step.getDiagrams()) {
									message.append(diagram.getCdocumentid());
								}
							}
							PdfPCell cell_step = new PdfPCell(new Paragraph(
									index2 + "." + i + "." + j + "、"
											+ step.getContent() 
											+ message.toString(), fontChinese2));
							cell_step.setColspan(6);
							cell_step.setPadding(0);
							cell_step.setLeading(0, 1.5f);
							// cell_step.setFixedHeight(15);
							cell_step
									.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
							cell_step
									.setVerticalAlignment(Element.ALIGN_BOTTOM);
							cell_step.setBorder(Rectangle.NO_BORDER);
							table3.addCell(cell_step);

							
							//工步表格相关内容
							WorkStepColsAction stepColsAction = new WorkStepColsAction();
							WorkStepColsContextAction contextAction = new WorkStepColsContextAction();
							// 列名
							List<WorkStepCols> stepList = (ArrayList<WorkStepCols>) stepColsAction
									.findWorkStepCols(step);
							// 空白部分
							table3.addCell(blank);
							// 工步表格列
							if (stepList != null && stepList.size() > 0) {
								PdfPTable table = new PdfPTable(stepList.size());
								for (int k = 0; k < stepList.size(); k++) {
									PdfPCell title = new PdfPCell(new Paragraph(
											stepList.get(k) + "", fontChinese2));
									// title.setFixedHeight(20);
									title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
									title.setVerticalAlignment(Element.ALIGN_MIDDLE);
									// title.setLeading(0,1.5f);
									table.addCell(title);

								}

								PdfPCell pcell = new PdfPCell(table);
								pcell.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
								pcell.setVerticalAlignment(Element.ALIGN_MIDDLE);
								pcell.setColspan(6);
								table3.addCell(pcell);
							}
							// 工步表格内容
							WorkStepColsContextAction stepColsContextAction = new WorkStepColsContextAction();
							
							List<WorkStepColsContext> colsContexts = new ArrayList<WorkStepColsContext>();
							List<List<WorkStepColsContext>> lists = new ArrayList<List<WorkStepColsContext>>();
							for (WorkStepCols workStepCols : stepList) {
								colsContexts = (ArrayList<WorkStepColsContext>) stepColsContextAction
										.findWorkStepColsContext(workStepCols);
								lists.add(colsContexts);
							}
							if (colsContexts != null && colsContexts.size() > 0) {
								PdfPTable table = new PdfPTable(stepList.size());
								for (int m = 0; m < colsContexts.size(); m++) {
									for (int n = 0; n < lists.size(); n++) {
										PdfPCell cell = new PdfPCell();

										cell = new PdfPCell(new Paragraph(
												lists.get(n).get(m)
														.toString(), fontChinese2));

										cell.setHorizontalAlignment(Element.ALIGN_CENTER);
										cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
										table.addCell(cell);
									}

								}
								PdfPCell cell = new PdfPCell(table);
								cell.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
								cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
								cell.setColspan(6);
								table3.addCell(cell);
							}
							
							
							// 工步备注
							if (step.getPayMessage() != null
									&& !step.getPayMessage().equals("")) {
								Paragraph paragraph = new Paragraph("注:"
										+ step.getPayMessage(), fontChinese2);
								// paragraph.setLeading(fontChinese2.getSize());

								PdfPCell cell_remark = new PdfPCell(paragraph);
								cell_remark.setColspan(6);
								cell_remark.setPadding(0);
								cell_remark.setPaddingLeft(10);
								// cell_remark.setFixedHeight(15);
								cell_remark.setLeading(0, 1.5f);
								cell_remark
										.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
								cell_remark
										.setVerticalAlignment(Element.ALIGN_BOTTOM);
								cell_remark.setBorder(Rectangle.NO_BORDER);
								table3.addCell(cell_remark);
							}

							// 工装设备
							Set<Equipment> equipments = step.getEquipments();
							// 辅材
							Set<SubMaterial> subMaterials = step.getMaterials();
							if (equipments.size() != 0) {
								StringBuffer equipment_message = new StringBuffer();
								// for (Equipment equipment : equipments) {
								// equipment_message.append(equipment
								// .getName());
								// equipment_message.append(",");
								//
								// }
								Object[] list = equipments.toArray();
								for (int k = 0; k < list.length; k++) {
									equipment_message.append(list[k]);
									if (k != list.length - 1) {
										equipment_message.append(",");
									}
								}
								PdfPCell cell_equipment = new PdfPCell(
										new Paragraph("["
												+ equipment_message.toString()
												+ "]", fontChinese2));
								cell_equipment.setColspan(6);
								cell_equipment.setPadding(0);
								cell_equipment.setPaddingLeft(10);
								// cell_equipment.setFixedHeight(15);
								cell_equipment.setLeading(0, 1.5f);
								cell_equipment
										.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
								cell_equipment
										.setVerticalAlignment(Element.ALIGN_BOTTOM);
								cell_equipment.setBorder(Rectangle.NO_BORDER);
								table3.addCell(cell_equipment);
							}
							if (subMaterials.size() != 0) {
								StringBuffer subMaterial_message = new StringBuffer();
								for (SubMaterial subMaterial : subMaterials) {
									subMaterial_message.append(subMaterial
											.getName());
									subMaterial_message.append(",");
								}
								PdfPCell cell_subMaterial = new PdfPCell(
										new Paragraph("["
												+ subMaterial_message
														.toString() + "]",
												fontChinese2));
								cell_subMaterial.setColspan(6);
								cell_subMaterial.setPadding(0);
								// cell_subMaterial.setPaddingLeft(10);
								// cell_subMaterial.setFixedHeight(15);
								cell_subMaterial.setLeading(0, 1.5f);
								cell_subMaterial
										.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
								cell_subMaterial
										.setVerticalAlignment(Element.ALIGN_BOTTOM);
								cell_subMaterial.setBorder(Rectangle.NO_BORDER);
								table3.addCell(cell_subMaterial);
							}
							j++;
						}
					}
				} else if (catalog.getType().equals(Constants.CATALOGTYPE_LJML)) {
//					Ensip ensip = null;
//					Ensip ensip = technology.getEnsip();// 结构
//					EnsipEntity ensipEntity = null; //技术手册变动有影响，暂时屏蔽
					
//					EnsipEntity ensipEntity = technology.getManual().getEnsipEntity(); // 对象
//					EnsipStructureAction action2 = new EnsipStructureAction();
//					EnsipStructure ensipStructure = action2
//							.findEnsipStructrueByEnsipAndEntity(ensip,
//									ensipEntity);
//					EnsipBomAction action3 = new EnsipBomAction();
					Set<EnsipBom> sets = technology.getEnsipBoms();
					List<EnsipBom> list = new ArrayList<EnsipBom>();
					for (EnsipBom ensipBom : sets) {
						list.add(ensipBom);
					}
					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_LJML, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);
					// 零组件目录表格
					String[] titles = { "序号", "名称", "图号", "数量", "图位", "备注" };
					for (int i = 0; i < titles.length; i++) {
						PdfPCell title = new PdfPCell(new Paragraph(titles[i],
								fontChinese2));
						title.setFixedHeight(20);
						title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
						title.setVerticalAlignment(Element.ALIGN_MIDDLE);
						table3.addCell(title);

					}
					if (list != null) {
						for (int i = 0; i < list.size(); i++) {
							for (int j = 0; j < titles.length; j++) {
								PdfPCell cell = new PdfPCell();
								switch (j) {
								case 0:
									cell = new PdfPCell(new Paragraph((i + 1)
											+ "", fontChinese2));
									break;
								case 1:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getChinaName(), fontChinese2));
									break;
								case 2:
									cell = new PdfPCell(new Paragraph("图号" + i,
											fontChinese2));
									break;
								case 3:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getCounts(), fontChinese2));
									break;
								case 4:
									cell = new PdfPCell(new Paragraph("图位" + i,
											fontChinese2));
									break;
								case 5:
									cell = new PdfPCell(new Paragraph("备注" + i,
											fontChinese2));
									break;
								default:
									break;
								}
								cell.setHorizontalAlignment(Element.ALIGN_CENTER);
								cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
								cell.setFixedHeight(20);
								table3.addCell(cell);

							}
						}
					}

				} else if (catalog.getType().equals(Constants.CATALOGTYPE_WSJC)) {
					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_WSJC, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);
				} else if (catalog.getType().equals(Constants.CATALOGTYPE_TYGZ)) {
					ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
					Set<Equipment> equipments = new HashSet<Equipment>();

					ProcessAction action = new ProcessAction();
					WorkStepAction action2 = new WorkStepAction();
					CatalogAction action3 = new CatalogAction();
					Catalog catalog1 = action3
							.findCatalogByType(Constants.CATALOGTYPE_GXNR);
//					Collection<ProcessEntity> prs = action
//							.findProcessByCatalogAndTechnology(catalog1,
//									technology);
					Collection<ProcessEntity> prs = null;
					// 全部的工步
					for (ProcessEntity process : prs) {
						Collection<WorkStep> sts = action2
								.findStepByProcess(process);
						for (WorkStep step : sts) {
							steps.add(step);
						}
					}

					// 工步下面的工装
					for (WorkStep step : steps) {
						Collection<Equipment> es = step.getEquipments();
						for (Equipment e : es) {
							if (e.getKind().equals("通用工装")) {
								equipments.add(e);
							}
						}
					}
					ArrayList<Equipment> list = new ArrayList<Equipment>();
					for (Equipment equipment : equipments) {
						list.add(equipment);
					}
					EquipmentSort sort = new EquipmentSort();
					Collections.sort(list, sort);

					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_TYGZ, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);

					// 通用工装目录表格
					String[] titles = { "序号", "名称", "规格", "备注" };
					for (int i = 0; i < titles.length; i++) {
						PdfPCell title = new PdfPCell(new Paragraph(titles[i],
								fontChinese2));
						title.setFixedHeight(20);
						if (i == 2) {
							title.setColspan(3);
						}
						title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
						title.setVerticalAlignment(Element.ALIGN_MIDDLE);
						table3.addCell(title);

					}
					if (list != null) {
						for (int i = 0; i < list.size(); i++) {
							for (int j = 0; j < titles.length; j++) {
								PdfPCell cell = new PdfPCell();
								switch (j) {
								case 0:
									cell = new PdfPCell(new Paragraph((i + 1)
											+ "", fontChinese2));
									break;
								case 1:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getName(), fontChinese2));
									break;
								case 2:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getSpec(), fontChinese2));
									break;
								case 3:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getRemark(), fontChinese2));
									break;
								default:
									break;
								}
								if (j == 2) {
									cell.setColspan(3);
								}
								cell.setHorizontalAlignment(Element.ALIGN_CENTER);
								cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
								cell.setFixedHeight(20);
								table3.addCell(cell);

							}
						}
					}
				} else if (catalog.getType().equals(Constants.CATALOGTYPE_ZYGZ)) {
					ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
					Set<Equipment> equipments = new HashSet<Equipment>();

					ProcessAction action = new ProcessAction();
					WorkStepAction action2 = new WorkStepAction();
					CatalogAction action3 = new CatalogAction();
					Catalog catalog1 = action3
							.findCatalogByType(Constants.CATALOGTYPE_GXNR);
//					Collection<ProcessEntity> prs = action
//							.findProcessByCatalogAndTechnology(catalog1,
//									technology);
					Collection<ProcessEntity> prs = null;
					// 全部的工步
					for (ProcessEntity process : prs) {
						Collection<WorkStep> sts = action2
								.findStepByProcess(process);
						for (WorkStep step : sts) {
							steps.add(step);
						}
					}

					// 工步下面的工装
					for (WorkStep step : steps) {
						Collection<Equipment> es = step.getEquipments();
						for (Equipment e : es) {
							if (e.getKind().equals("专用工装")) {
								equipments.add(e);
							}
						}
					}
					ArrayList<Equipment> list = new ArrayList<Equipment>();
					for (Equipment equipment : equipments) {
						list.add(equipment);
					}
					EquipmentSort sort = new EquipmentSort();
					Collections.sort(list, sort);

					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_ZYGZ, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);

					// 通用工装目录表格
					String[] titles = { "序号", "名称", "图号、型号、规格", "备注" };
					for (int i = 0; i < titles.length; i++) {
						PdfPCell title = new PdfPCell(new Paragraph(titles[i],
								fontChinese2));
						title.setFixedHeight(20);
						if (i == 2) {
							title.setColspan(3);
						}
						title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
						title.setVerticalAlignment(Element.ALIGN_MIDDLE);
						table3.addCell(title);

					}
					if (list != null) {
						for (int i = 0; i < list.size(); i++) {
							for (int j = 0; j < titles.length; j++) {
								PdfPCell cell = new PdfPCell();
								switch (j) {
								case 0:
									cell = new PdfPCell(new Paragraph((i + 1)
											+ "", fontChinese2));
									break;
								case 1:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getName(), fontChinese2));
									break;
								case 2:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getSpec(), fontChinese2));
									break;
								case 3:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getRemark(), fontChinese2));
									break;
								default:
									break;
								}
								if (j == 2) {
									cell.setColspan(3);
								}
								cell.setHorizontalAlignment(Element.ALIGN_CENTER);
								cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
								cell.setFixedHeight(20);
								table3.addCell(cell);

							}
						}
					}
				} else if (catalog.getType().equals(Constants.CATALOGTYPE_SB)) {
					ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
					Set<Equipment> equipments = new HashSet<Equipment>();

					ProcessAction action = new ProcessAction();
					WorkStepAction action2 = new WorkStepAction();
					CatalogAction action3 = new CatalogAction();
					Catalog catalog1 = action3
							.findCatalogByType(Constants.CATALOGTYPE_GXNR);
//					Collection<ProcessEntity> prs = action
//							.findProcessByCatalogAndTechnology(catalog1,
//									technology);
					Collection<ProcessEntity> prs = null;
					// 全部的工步
					for (ProcessEntity process : prs) {
						Collection<WorkStep> sts = action2
								.findStepByProcess(process);
						for (WorkStep step : sts) {
							steps.add(step);
						}
					}

					// 工步下面的工装
					for (WorkStep step : steps) {
						Collection<Equipment> es = step.getEquipments();
						for (Equipment e : es) {
							if (e.getKind().equals("设备")) {
								equipments.add(e);
							}
						}
					}
					ArrayList<Equipment> list = new ArrayList<Equipment>();
					for (Equipment equipment : equipments) {
						list.add(equipment);
					}
					EquipmentSort sort = new EquipmentSort();
					Collections.sort(list, sort);

					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_SB, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);

					// 通用工装目录表格
					String[] titles = { "序号", "名称", "图号、型号、规格", "备注" };
					for (int i = 0; i < titles.length; i++) {
						PdfPCell title = new PdfPCell(new Paragraph(titles[i],
								fontChinese2));
						title.setFixedHeight(20);
						if (i == 2) {
							title.setColspan(3);
						}
						title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
						title.setVerticalAlignment(Element.ALIGN_MIDDLE);
						table3.addCell(title);

					}
					if (list != null) {
						for (int i = 0; i < list.size(); i++) {
							for (int j = 0; j < titles.length; j++) {
								PdfPCell cell = new PdfPCell();
								switch (j) {
								case 0:
									cell = new PdfPCell(new Paragraph((i + 1)
											+ "", fontChinese2));
									break;
								case 1:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getName(), fontChinese2));
									break;
								case 2:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getSpec(), fontChinese2));
									break;
								case 3:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getRemark(), fontChinese2));
									break;
								default:
									break;
								}
								if (j == 2) {
									cell.setColspan(3);
								}
								cell.setHorizontalAlignment(Element.ALIGN_CENTER);
								cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
								cell.setFixedHeight(20);
								table3.addCell(cell);

							}
						}
					}
				} else if (catalog.getType().equals(Constants.CATALOGTYPE_BZYJ)) {
					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_BZYJ, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);
				} else if (catalog.getType().equals(Constants.CATALOGTYPE_FC)) {
					ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
					Set<SubMaterial> subs = new HashSet<SubMaterial>();
					ProcessAction action = new ProcessAction();
					WorkStepAction action2 = new WorkStepAction();
					CatalogAction action3 = new CatalogAction();
					Catalog catalog1 = action3
							.findCatalogByType(Constants.CATALOGTYPE_GXNR);
//					Collection<ProcessEntity> prs = action
//							.findProcessByCatalogAndTechnology(catalog1,
//									technology);
					Collection<ProcessEntity> prs = null;
					// 全部的工步
					for (ProcessEntity process : prs) {
						Collection<WorkStep> sts = action2
								.findStepByProcess(process);
						for (WorkStep step : sts) {
							steps.add(step);
						}
					}
					// 工步下面全部的辅材
					for (WorkStep step : steps) {
						Collection<SubMaterial> subMaterials = step
								.getMaterials();
						for (SubMaterial s : subMaterials) {
							subs.add(s);
						}
					}
					ArrayList<SubMaterial> list = new ArrayList<SubMaterial>();
					for (SubMaterial subMaterial : subs) {
						list.add(subMaterial);
					}
					SubMaterialSort sort = new SubMaterialSort();
					Collections.sort(list, sort);

					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_FC, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);

					// 辅助材料目录表格
					String[] titles = { "序号", "名称", "规格", "备注" };
					for (int i = 0; i < titles.length; i++) {
						PdfPCell title = new PdfPCell(new Paragraph(titles[i],
								fontChinese2));
						title.setFixedHeight(20);
						if (i == 2) {
							title.setColspan(3);
						}
						title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
						title.setVerticalAlignment(Element.ALIGN_MIDDLE);
						table3.addCell(title);

					}
					if (list != null) {
						for (int i = 0; i < list.size(); i++) {
							for (int j = 0; j < titles.length; j++) {
								PdfPCell cell = new PdfPCell();
								switch (j) {
								case 0:
									cell = new PdfPCell(new Paragraph((i + 1)
											+ "", fontChinese2));
									break;
								case 1:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getName(), fontChinese2));
									break;
								case 2:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getParameter(), fontChinese2));
									break;
								case 3:
									cell = new PdfPCell(new Paragraph(list.get(
											i).getRemark(), fontChinese2));
									break;
								default:
									break;
								}
								if (j == 2) {
									cell.setColspan(3);
								}
								cell.setHorizontalAlignment(Element.ALIGN_CENTER);
								cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
								cell.setFixedHeight(20);
								table3.addCell(cell);

							}
						}
					}
				} else if (catalog.getType().equals(Constants.CATALOGTYPE_GZK)) {
					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_GZK, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);
				} else if (catalog.getType().equals(Constants.CATALOGTYPE_JT)) {
					// 标题
					PdfPCell cell_title = new PdfPCell(new Paragraph(index2
							+ "、" + Constants.CATALOGTYPE_JT, fontChinese));
					cell_title.setColspan(6);
					cell_title.setFixedHeight(40);
					cell_title.setHorizontalAlignment(Element.ALIGN_LEFT);// 设置内容水平靠左显示
					cell_title.setVerticalAlignment(Element.ALIGN_MIDDLE);
					cell_title.setBorder(Rectangle.NO_BORDER);
					table3.addCell(cell_title);

					ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
					Set<Diagram> diagrams = new HashSet<Diagram>();
					ProcessAction action = new ProcessAction();
					WorkStepAction action2 = new WorkStepAction();
					CatalogAction action3 = new CatalogAction();
					Catalog catalog1 = action3
							.findCatalogByType(Constants.CATALOGTYPE_GXNR);
//					Collection<ProcessEntity> prs = action
//							.findProcessByCatalogAndTechnology(catalog1,
//									technology);
					Collection<ProcessEntity> prs = null;
					// 全部的工步
					for (ProcessEntity process : prs) {
						Collection<WorkStep> sts = action2
								.findStepByProcess(process);
						for (WorkStep step : sts) {
							steps.add(step);
						}
					}
					// 工步下面全部的简图
					for (WorkStep workStep : steps) {
						Collection<Diagram> ds = workStep.getDiagrams();
						for (Diagram diagram : ds) {
							diagrams.add(diagram);
						}
					}
					ArrayList<Diagram> list = new ArrayList<Diagram>();
					for (Diagram diagram : diagrams) {
						list.add(diagram);
					}
					DiagramAction action4 = new DiagramAction();
					PnlEamoisBrowser pnl = new PnlEamoisBrowser();
					for (Diagram e : diagrams) {
						String id = e.getCdocumentid();
						String var = e.getCdocumentver();
						DocumentView doc = action4
								.getDiagramByIdAndVer(id, var);
						ViewDocument viewDoc = action4.getDocumentByIdAndVer2(
								doc.getCode(), doc.getVarsion());
						String filePath = pnl.getDocFromFtp(viewDoc);
						// System.err.println(filePath);
						Image image = Image.getInstance(filePath);
						images.add(image);
					}
					// Image image=
					// Image.getInstance("D:\\Users\\Administrator\\Desktop\\坚持.jpg");
					// images.add(image);
					// Image image2= Image.getInstance("G:\\好图\\2222.jpg");
					// images.add(image2);
				}
				index2++;

			}

			document.add(table3);
			// document.add(image);
			if (images != null && images.size() > 0) {
				for (Image img : images) {
					document.add(img);
				}
			}
			document.newPage();
			// 表格
			PdfPCell cell_table = new PdfPCell();
			// 关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		// 用Windows集成方式打开
		Browse browsefile = new Browse(Browse.BROWSEDOC_RETURN);
		browsefile.browseFile(path);

	}*/
	
	// Word导出方法
	private static void createWord(String path, Collection<Technology> technologies) {
		Rectangle rect=PageSize.A4;
		Document document = new Document(rect, 20, 20, 20, 20);
		try {
			// 输出为文件
			RtfWriter2 writer =RtfWriter2.getInstance(document, new FileOutputStream(path));
//			PdfWriter writer =PdfWriter.getInstance(document, new FileOutputStream(path));
			// 打开文档
			document.open();
			BaseFont bfChinese = BaseFont.createFont("STSongStd-Light",
					"UniGB-UCS2-H", false);
			com.lowagie.text.Font fontChinese = new com.lowagie.text.Font(
					bfChinese, 20, Font.BOLD);
			com.lowagie.text.Font fontChinese2 = new com.lowagie.text.Font(
					bfChinese,14,Font.PLAIN);
			com.lowagie.text.Font fontChinese3 = new com.lowagie.text.Font(
					bfChinese,17,Font.BOLD);
			Paragraph paraHeader = new Paragraph();
//			paraHeader.add(new Phrase(technology.getManual().getManualEngine()+"\t\t\t\t\t\t\t\t\t\t\t\t\t第 "));
			paraHeader.add(new RtfPageNumber());
//			paraHeader.add(new Phrase("页 共"));
//			paraHeader.add(new RtfTotalPageNumber());
			paraHeader.add(new Phrase(" 页"));
			// 添加页眉   
			HeaderFooter header = new RtfHeaderFooter(paraHeader);
			header.setAlignment(Element.ALIGN_LEFT);
			header.setBorderWidthBottom(22);
			document.setHeader(header); 
			
			for (Technology technology : technologies) {
				CatalogAction catalogAction = new CatalogAction();
				//针对不同的工艺存在不同的工艺目录
				ArrayList<Catalog> catalogs= (ArrayList<Catalog>)catalogAction.findAllCatalogByTech(technology);
				// 在word文件中写入文字
				Paragraph conData = new Paragraph("内部资料");
				conData.setAlignment(Element.ALIGN_LEFT);
				conData.setFont(fontChinese3);
				conData.setSpacingBefore(5);
				conData.setFirstLineIndent(20);
				document.add(conData);
//				Paragraph conData2 = new Paragraph("批准："+"\t\t\t\t\t\t\t\t\t适用机型："+technology.getManual().getManualEngine());
				Paragraph conData2 = new Paragraph("批准："+"\t\t\t\t\t\t\t\t\t适用机型：");
				conData2.setAlignment(Element.ALIGN_LEFT);
				conData2.setLeading(Element.ALIGN_LEFT);
				conData2.setSpacingBefore(5);
				conData2.setFirstLineIndent(20);
				conData2.setFont(fontChinese3);
				document.add(conData2);
				// 标题
				Paragraph context = new Paragraph("中国人民解放军第五七一九工厂");
				 context.setAlignment(Element.ALIGN_CENTER);
				 context.setFont(fontChinese);
				 // 离上一段落（标题）空的行数
				 context.setSpacingBefore(5);
				 // 设置第一行空的列数
//				 context.setFirstLineIndent(20);
				 document.add(context);
				// 标题
//				 Paragraph context2 = new Paragraph("航空发动机"+ technology.getType() + "工艺规程");
				 Paragraph context2 = new Paragraph("航空发动机"+ "" + "工艺规程");
				 context2.setAlignment(Element.ALIGN_CENTER);
				 context2.setFont(fontChinese);
				 context2.setSpacingBefore(5);
				 context2.setExtraParagraphSpace(55);
//				 context2.setFirstLineIndent(20);
				 document.add(context2);
				// 工艺编码
				 Paragraph context3 = new Paragraph(technology.getCode());
				 context3.setAlignment(Element.ALIGN_CENTER);
				 context3.setFont(fontChinese);
				 context3.setSpacingBefore(5);
				 context3.setFirstLineIndent(20);
				 document.add(context3);
				// 分隔
				 Paragraph contextLine = new Paragraph("___________________________________________________________________");
				 contextLine.setAlignment(Element.ALIGN_CENTER);
				 contextLine.setFont(fontChinese2);
				 contextLine.setSpacingBefore(5);
				 contextLine.setFirstLineIndent(20);
				 document.add(contextLine);
				 Paragraph contextName = new Paragraph(technology.getName());
				 contextName.setAlignment(Element.ALIGN_CENTER);
				 contextName.setFont(fontChinese);
				 contextName.setSpacingBefore(5);
				 contextName.setFirstLineIndent(20);
				 document.add(contextName);
				 Paragraph contextBlank = new Paragraph("");
				 contextBlank.setAlignment(Element.ALIGN_CENTER);
				 contextBlank.setFont(fontChinese);
				 contextBlank.setSpacingBefore(450);
				 contextBlank.setFirstLineIndent(20);
				 document.add(contextBlank);
				// 分隔
				 document.add(contextLine);

				 Paragraph contextComp = new Paragraph("中国人民解放军第五七一九工厂");
				 contextComp.setAlignment(Element.ALIGN_CENTER);
				 contextComp.setFont(fontChinese2);
				 contextComp.setSpacingBefore(5);
				 contextComp.setFirstLineIndent(20);
				 document.add(contextComp);
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月");
				Date date = new Date();
				String day = sdf.format(date);
				 Paragraph contextDate = new Paragraph(day);
				 contextDate.setAlignment(Element.ALIGN_CENTER);
				 contextDate.setFont(fontChinese);
				 contextDate.setSpacingBefore(5);
				 contextDate.setFirstLineIndent(20);
				 document.add(contextDate);
				document.newPage();

				Paragraph nulu = new Paragraph("目录", fontChinese2);
				nulu.setAlignment(Element.ALIGN_CENTER);
				nulu.setFont(fontChinese2);
//				nulu.setSpacingBefore(5);
				nulu.setFirstLineIndent(20);
				document.add(nulu);
				//添加工序内容目录，这个系统不会显示、但导出用
				Catalog cat = new Catalog();
				cat.setName(Constants.CATALOGTYPE_GXNR);
				catalogs.add(0, cat);
//				String[] cats = {"工序内容","零组件目录","无损检查目录","通用工装目录","专用工装目录","设备目录","标准样件和标准件目录","辅助材料目录","计量器具目录","故障库","附件","简图"};
				int index = 1;
				for (Catalog catalog : catalogs) {
					String con = index + " " + catalog;
					Paragraph cata= new Paragraph(con, fontChinese2);
					cata.setFont(fontChinese2);
//					cata.setSpacingBefore(5);
					cata.setFirstLineIndent(20);
					document.add(cata);
					// 工序内容下工步
					if (catalog.toString().equals(Constants.CATALOGTYPE_GXNR)) {
						ProcessAction action = new ProcessAction();
						Collection<ProcessEntity> pros = action
								.findProcessByTechnology(technology);
						int num = 1;
						for (ProcessEntity processEntity : pros) {
							Paragraph cellProcess = new Paragraph(index
									+ "." + num + " " + processEntity.getName(),
									fontChinese2);
							cellProcess.setFont(fontChinese2);
//							cellProcess.setSpacingBefore(5);
							cellProcess.setFirstLineIndent(20);
							document.add(cellProcess);
							num++;
						}
					}
					index++;
				}
				
				document.newPage();
				
				// 循环添加每个工艺类型内容
				int index2 = 1;
				
				for (Catalog catalog : catalogs) {
					// 总则
					if (catalog.toString().equals(Constants.CATALOGTYPE_ZZ)) {
//						GengralRulesAction action = new GengralRulesAction();
//						GengralRules gengralRules = action
//								.findGengralRulesByCatalogAndTechnology(catalog,
//										technology);
//						// 标题
//						Paragraph cell_title = new Paragraph(index2
//								+ "、" + Constants.CATALOGTYPE_ZZ, fontChinese2);
//						cell_title.setFont(fontChinese2);
////						cell_title.setSpacingBefore(5);
//						cell_title.setFirstLineIndent(20);
//						document.add(cell_title);
	//
//						// 内容
//						Paragraph cell_message = new Paragraph(
//								gengralRules == null ? ""
//										: gengralRules.getContent(), fontChinese2);
//						cell_message.setFont(fontChinese2);
////						cell_message.setSpacingBefore(5);
//						cell_message.setFirstLineIndent(20);
//						document.add(cell_message);

					}// 工序内容
					else if (catalog.toString().equals(Constants.CATALOGTYPE_GXNR)) {
						ProcessAction action = new ProcessAction();
						Collection<ProcessEntity> procs = action
								.findProcessByTechnology(technology);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_GXNR, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						// 内容
						int i = 1;
						for (ProcessEntity process : procs) {
							Paragraph cell_message = new Paragraph(
									index2 + "." + i + "、" + process.getName(),
									fontChinese2);
							cell_message.setFont(fontChinese2);
//							cell_message.setSpacingBefore(5);
							cell_message.setFirstLineIndent(20);
							document.add(cell_message);
							//工序表格相关内容
							ProcessEntityColsAction colsAction = new ProcessEntityColsAction();
							ProcessEntityColsContextAction colsContextAction = new ProcessEntityColsContextAction();
							// 列名
							List<ProcessEntityCols> colsList = (ArrayList<ProcessEntityCols>) colsAction
									.findEnsipEntityCols(process);
							// 空白部分
							Paragraph blank = new Paragraph("",
									fontChinese2);
							blank.setFont(fontChinese2);
//							blank.setSpacingBefore(5);
							blank.setFirstLineIndent(20);
							document.add(blank);
							// 工序表格列
							Table table =null;
							if (colsList != null && colsList.size() > 0) {
								table = new Table(colsList.size());
								for (int j = 0; j < colsList.size(); j++) {
									Cell title = new Cell(new Paragraph(
											colsList.get(j) + "", fontChinese2));
									// title.setFixedHeight(20);
									title.setHeader(true);
									title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
									title.setVerticalAlignment(Element.ALIGN_MIDDLE);
									// title.setLeading(0,1.5f);
									table.addCell(title);
									table.endHeaders();

								}
							}
							// 工序表格内容
							List<ProcessEntityColsContext> colsContext = new ArrayList<ProcessEntityColsContext>();
							List<List<ProcessEntityColsContext>> allColsContext = new ArrayList<List<ProcessEntityColsContext>>();
							for (ProcessEntityCols processEntityCols : colsList) {
								colsContext = (ArrayList<ProcessEntityColsContext>) colsContextAction
										.findEnsipEntityColsContext(processEntityCols);
								allColsContext.add(colsContext);
							}
							if (colsContext != null && colsContext.size() > 0) {
								//行
								for (int m = 0; m < colsContext.size(); m++) {
									//记录cell
									List<Cell> cells = new ArrayList<Cell>();
									//列
									for (int n = 0; n < allColsContext.size(); n++) {
										Cell cell =  new Cell(new Paragraph(
												allColsContext.get(n).get(m)
														.toString(), fontChinese2));

										cell.setHorizontalAlignment(Element.ALIGN_CENTER);
										cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
										cells.add(cell);
										
//										table.addCell(cell);
									}
									boolean isEmpty =true;//整行都为空数据
									for (Cell cell : cells) {
										//如果整行有一些有数据则记录
										if(!cell.isEmpty())
											isEmpty = false;
									}
									if(!isEmpty)
									for (Cell cell : cells) {
										table.addCell(cell);
									}
								}
							}
							
							if(table!=null){
								document.add(table);
							}
							if (process.getRemark() != null
									&& !process.getRemark().equals("")) {
								Paragraph cell_remark = new Paragraph("注:"
										+ process.getRemark(), fontChinese2);
								cell_remark.setLeading(10f);
								cell_remark.setFont(fontChinese2);
//								cell_remark.setSpacingBefore(5);
								cell_remark.setFirstLineIndent(20);
								document.add(cell_remark);
							}
							
							//微分测量表
							DifferentialMeaTemplateAction templateAction = new DifferentialMeaTemplateAction();
							Collection<DifferentialMeaTemplate> templates = templateAction.findDifferentMeas(process);
							if(templates.size()!=0){
								// 标题
								Paragraph cell_template = new Paragraph("微分测量表（工序）", fontChinese2);
								cell_template.setSpacingBefore(20);
								cell_template.setFont(fontChinese2);
								cell_template.setFirstLineIndent(20);
								document.add(cell_template);
							}
							int num = 1;
							for (DifferentialMeaTemplate template : templates) {
								//名称
								Paragraph cell_detail = new Paragraph(num+"、"+template.getName(), fontChinese2);
								cell_detail.setFont(fontChinese2);
								cell_detail.setFirstLineIndent(32);
//								cell_detail.setSpacingBefore(10);
//								cell_detail.setSpacingAfter(500);
								document.add(cell_detail);
								num++;
								
								//微分测量表具体模样
								MeaPolygonAction mAction = new MeaPolygonAction();
								ArrayList<MeaPolygon> polygons=(ArrayList<MeaPolygon>)mAction.findGraphPolygonByTemplate(template);
								MeaContentAction cAction = new MeaContentAction();
								ArrayList<MeaContent> contents =(ArrayList<MeaContent>) cAction.findGraphContentByTemplate(template, "false");
								PolygonSort sort = new PolygonSort();
								Collections.sort(polygons, sort);
								double y = 5.0;//记录起始Y值，用于多个表格的开头判断（表格复杂，分为表中表）
								//微分测量表大表格
								Table meatable = new Table(1);
								PolygonUtil util = new PolygonUtil();
								util.handleTable(y,polygons,contents);
								Collection<Table> tables = util.getTables();
								for (Table table2 : tables) {
									meatable.insertTable(table2);
								}
								document.add(meatable);
							}
							
							StoppageAndProcessStructureAction relationAction = new StoppageAndProcessStructureAction();
							//工序相关的故障
							Collection<StoppageAndProcessStructure> relationList = relationAction.findStoppageAndProcessByProcess(process);
							ArrayList<Stoppage> stoppages = new ArrayList<Stoppage>();
							for (StoppageAndProcessStructure stoppageAndProcessStructure : relationList) {
								stoppages.add(stoppageAndProcessStructure.getStoppage());
							}
							
							Table table3 =null;
							// 零组件目录表格
							String[] titles = { "序号", "故障名称", "故障描述" };
							table3 = new Table(titles.length);
							for (int j = 0; j < titles.length; j++) {
								Cell title = new Cell(new Paragraph(titles[j],
										fontChinese2));
//								title.setBorder(1);
								title.setHeader(true);
//								title.setFixedHeight(20);
								title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
								title.setVerticalAlignment(Element.ALIGN_MIDDLE);
								table3.addCell(title);
								table3.endHeaders();

							}
							if (stoppages != null&&stoppages.size()!=0) {
								for (int j = 0; j < stoppages.size(); j++) {
									for (int k = 0; k < titles.length; k++) {
										Cell cell = new Cell();
										switch (k) {
										case 0:
											cell = new Cell(new Paragraph((j + 1)+ "", fontChinese2));
											break;
										case 1:
											cell = new Cell(new Paragraph(stoppages.get(j).getName(), fontChinese2));
											break;
										case 2:
											cell = new Cell(new Paragraph(stoppages.get(j).getDescribe(),fontChinese2));
											break;
										default:
											break;
										}
										cell.setHorizontalAlignment(Element.ALIGN_CENTER);
										cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//										cell.setFixedHeight(20);
										table3.addCell(cell);

									}
								}
								// 标题
								Paragraph cell_stoppage = new Paragraph("故障", fontChinese2);
								cell_stoppage.setFont(fontChinese2);
//								cell_title.setSpacingBefore(5);
								cell_stoppage.setFirstLineIndent(20);
								document.add(cell_stoppage);
								document.add(table3);
							}
//							i++;
							//工序下的工步
							WorkStepAction action2 = new WorkStepAction();
							Collection<WorkStep> steps = action2
									.findStepByProcess(process);
							int j = 1;
							for (WorkStep step : steps) {
								StringBuffer message = new StringBuffer();
								if (step.getDiagrams().size() != 0) {
									for (Diagram diagram : step.getDiagrams()) {
										message.append(diagram.getCdocumentid());
									}
								}
//								Paragraph cell_step = new Paragraph(
//										index2 + "." + i + "." + j + "、"+ step.getContent() + message.toString(), fontChinese2);
								Paragraph cell_step = new Paragraph(
										index2 + "." + i + "." + j + "、"+ step.getContent(), fontChinese2);
								cell_step.setFont(fontChinese2);
//								cell_step.setSpacingBefore(5);
								cell_step.setFirstLineIndent(20);
								document.add(cell_step);
								
//								Paragraph cell_con = new Paragraph(step.getContent(), fontChinese2);
//								cell_con.setFont(fontChinese2);
////								cell_con.setSpacingBefore(5);
//								cell_con.setFirstLineIndent(40);
//								document.add(cell_con);
								
								
								//工步表格相关内容
								WorkStepColsAction stepColsAction = new WorkStepColsAction();
								WorkStepColsContextAction contextAction = new WorkStepColsContextAction();
								// 列名
								List<WorkStepCols> stepList = (ArrayList<WorkStepCols>) stepColsAction
										.findWorkStepCols(step);
								// 空白部分
								document.add(blank);
								// 工步表格列
								Table table2 = null;
								if (stepList != null && stepList.size() > 0) {
									table2 = new Table(stepList.size());
									for (int k = 0; k < stepList.size(); k++) {
										Cell title = new Cell(new Paragraph(
												stepList.get(k) + "", fontChinese2));
										title.setHeader(true);
										title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
										title.setVerticalAlignment(Element.ALIGN_MIDDLE);
										table2.addCell(title);
										table2.endHeaders();
									}
								}
								// 工步表格内容
//								WorkStepColsContextAction stepColsContextAction = new WorkStepColsContextAction();
								List<WorkStepColsContext> colsContexts = new ArrayList<WorkStepColsContext>();
								List<List<WorkStepColsContext>> lists = new ArrayList<List<WorkStepColsContext>>();
								for (WorkStepCols workStepCols : stepList) {
									colsContexts = (ArrayList<WorkStepColsContext>) contextAction
											.findWorkStepColsContext(workStepCols);
									lists.add(colsContexts);
								}
								if (colsContexts != null && colsContexts.size() > 0) {
//									 table = new Table(stepList.size());
									//行数
									for (int m = 0; m < colsContexts.size(); m++) {
										//记录cell
										List<Cell> cells = new ArrayList<Cell>();
										//列数
										for (int n = 0; n < lists.size(); n++) {
											Cell cell = new Cell(new Paragraph(
													lists.get(n).get(m)
															.toString(), fontChinese2));

											cell.setHorizontalAlignment(Element.ALIGN_CENTER);
											cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
											cells.add(cell);
										}
										boolean isEmpty =true;//整行都为空数据
										//如果整行有数据就添加到表格
										for (Cell cell : cells) {
											if(!cell.isEmpty())
												isEmpty = false;
										}
										if(!isEmpty)
										for (Cell cell : cells) {
											table2.addCell(cell);
										}
									}
								}
								if(table2!=null){
									document.add(table2);
								}
								// 工步备注
								if (step.getPayMessage() != null
										&& !step.getPayMessage().equals("")) {
									Paragraph cell_remark = new Paragraph("注:"
											+ step.getPayMessage(), fontChinese2);
									cell_remark.setFont(fontChinese2);
//									cell_remark.setSpacingBefore(5);
									cell_remark.setFirstLineIndent(20);
									document.add(cell_remark);
								}
								

								// 工装
								Set<Equipment> equipments = step.getEquipments();
								//设备
								Set<Device> devices = step.getDevices();
								// 辅材
								Set<SubMaterial> subMaterials = step.getMaterials();
								// 计量器具
								Set<Instrument> instruments = step.getInstruments();
								if (equipments.size() != 0) {
									StringBuffer equipment_message = new StringBuffer();
									Object[] list = equipments.toArray();
									for (int k = 0; k < list.length; k++) {
										equipment_message.append(list[k]);
										if (k != list.length - 1) {
											equipment_message.append(",");
										}
									}
									Paragraph cell_equipment = 
											new Paragraph("["
													+ equipment_message.toString()
													+ "]", fontChinese2);
									cell_equipment.setFont(fontChinese2);
//									cell_equipment.setSpacingBefore(5);
									cell_equipment.setFirstLineIndent(20);
									document.add(cell_equipment);
								}
								if (subMaterials.size() != 0) {
									StringBuffer subMaterial_message = new StringBuffer();
									Object[] list = subMaterials.toArray();
									for (int k = 0; k < list.length; k++) {
										subMaterial_message.append(list[k]);
										if (k != list.length - 1) {
											subMaterial_message.append(",");
										}
									}
									Paragraph cell_subMaterial = 
											new Paragraph("["
													+ subMaterial_message
															.toString() + "]",
													fontChinese2);
									cell_subMaterial.setFont(fontChinese2);
//									cell_subMaterial.setSpacingBefore(5);
									cell_subMaterial.setFirstLineIndent(20);
									document.add(cell_subMaterial);
								}
								if (devices.size() != 0) {
									StringBuffer device_message = new StringBuffer();
									Object[] list = devices.toArray();
									for (int k = 0; k < list.length; k++) {
										device_message.append(list[k]);
										if (k != list.length - 1) {
											device_message.append(",");
										}
									}
									Paragraph cell_device = 
											new Paragraph("["
													+ device_message.toString()
													+ "]", fontChinese2);
									cell_device.setFont(fontChinese2);
//									cell_device.setSpacingBefore(5);
									cell_device.setFirstLineIndent(20);
									document.add(cell_device);
								}
								
								if (instruments.size() != 0) {
									StringBuffer instrument_message = new StringBuffer();
									Object[] list = instruments.toArray();
									for (int k = 0; k < list.length; k++) {
										instrument_message.append(list[k]);
										if (k != list.length - 1) {
											instrument_message.append(",");
										}
									}
									Paragraph cell_instrument = 
											new Paragraph("["
													+ instrument_message.toString()
													+ "]", fontChinese2);
									cell_instrument.setFont(fontChinese2);
//									cell_equipment.setSpacingBefore(5);
									cell_instrument.setFirstLineIndent(20);
									document.add(cell_instrument);
								}
								
								
								

								//微分测量表
								Collection<DifferentialMeaTemplate> stepTemplates = templateAction.findDifferentMeas(step);
								if(stepTemplates.size()!=0){
									// 标题
									Paragraph cell_template = new Paragraph("微分测量表(工步)", fontChinese2);
									cell_template.setSpacingBefore(20);
									cell_template.setFont(fontChinese2);
									cell_template.setFirstLineIndent(20);
									document.add(cell_template);
								}
								int count = 1;
								for (DifferentialMeaTemplate template : stepTemplates) {
									//名称
									Paragraph cell_detail = new Paragraph(count+"、"+template.getName(), fontChinese2);
									cell_detail.setFont(fontChinese2);
									cell_detail.setFirstLineIndent(32);
//									cell_detail.setSpacingBefore(10);
//									cell_detail.setSpacingAfter(500);
									document.add(cell_detail);
									count++;
									
									
									//微分测量表具体模样
									MeaPolygonAction mAction = new MeaPolygonAction();
									ArrayList<MeaPolygon> polygons=(ArrayList<MeaPolygon>)mAction.findGraphPolygonByTemplate(template);
									MeaContentAction cAction = new MeaContentAction();
									ArrayList<MeaContent> contents =(ArrayList<MeaContent>) cAction.findGraphContentByTemplate(template, "false");
									PolygonSort sort = new PolygonSort();
									Collections.sort(polygons, sort);
									double y = 5.0;//记录起始Y值，用于多个表格的开头判断（表格复杂，分为表中表）
									//微分测量表大表格
									Table meatable = new Table(1);
									PolygonUtil util = new PolygonUtil();
									util.handleTable(y,polygons,contents);
									Collection<Table> tables = util.getTables();
									for (Table tab : tables) {
										meatable.insertTable(tab);
									}
									document.add(meatable);
								}
								
								
//								StoppageAndProcessStructureAction relationAction = new StoppageAndProcessStructureAction();
								//工步相关的故障
								Collection<StoppageAndProcessStructure> relationList2 = relationAction.findStoppageAndProcessByProcess(step);
								ArrayList<Stoppage> stoppages2 = new ArrayList<Stoppage>();
								for (StoppageAndProcessStructure stoppageAndProcessStructure : relationList2) {
									stoppages2.add(stoppageAndProcessStructure.getStoppage());
								}
								
								Table table4 =null;
								// 零组件目录表格
//								String[] titles2 = { "序号", "故障名称", "故障描述" };
								table4 = new Table(titles.length);
								for (int m = 0; m < titles.length; m++) {
									Cell title = new Cell(new Paragraph(titles[m],
											fontChinese2));
//									title.setBorder(1);
									title.setHeader(true);
//									title.setFixedHeight(20);
									title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
									title.setVerticalAlignment(Element.ALIGN_MIDDLE);
									table4.addCell(title);
									table4.endHeaders();

								}
								if (stoppages2 != null&&stoppages2.size()!=0) {
									for (int m = 0; m < stoppages2.size(); m++) {
										for (int k = 0; k < titles.length; k++) {
											Cell cell = new Cell();
											switch (k) {
											case 0:
												cell = new Cell(new Paragraph((m + 1)+ "", fontChinese2));
												break;
											case 1:
												cell = new Cell(new Paragraph(stoppages2.get(m).getName(), fontChinese2));
												break;
											case 2:
												cell = new Cell(new Paragraph(stoppages2.get(m).getDescribe(),fontChinese2));
												break;
											default:
												break;
											}
											cell.setHorizontalAlignment(Element.ALIGN_CENTER);
											cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//											cell.setFixedHeight(20);
											table4.addCell(cell);

										}
									}
									// 标题
									Paragraph cell_stoppage = new Paragraph("故障", fontChinese2);
									cell_stoppage.setFont(fontChinese2);
//									cell_title.setSpacingBefore(5);
									cell_stoppage.setFirstLineIndent(20);
									document.add(cell_stoppage);
									document.add(table4);
								}
								
								
								j++;
							}
							i++;
						}
						
					
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_LJML)) {
						Set<EnsipBom> sets = technology.getEnsipBoms();
						List<EnsipBom> list = new ArrayList<EnsipBom>();
						for (EnsipBom ensipBom : sets) {
							list.add(ensipBom);
						}
						PartSort sort = new PartSort();
						Collections.sort(list, sort);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_LJML, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						Table table3 = getWordTable();
						// 零组件目录表格
						String[] titles = { "序号", "名称", "图号", "数量", "图位", "备注" };
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
//							title.setBorder(1);
							title.setHeader(true);
//							title.setFixedHeight(20);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table3.addCell(title);
							table3.endHeaders();

						}
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(list.get(
												i).getChinaName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(list.get(
												i).getCounts(), fontChinese2));
										break;
									case 4:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									case 5:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									default:
										break;
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table3.addCell(cell);

								}
							}
						}
						document.add(table3);
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_WSJC)) {
						Set<EnsipBom> sets = technology.getEnsipBoms();
						List<EnsipBom> list = new ArrayList<EnsipBom>();
						for (EnsipBom ensipBom : sets) {
							if("1".equals(ensipBom.getIsNondestructive())){
								list.add(ensipBom);
							}
						}
						PartSort sort = new PartSort();
						Collections.sort(list, sort);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_WSJC, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						Table table3 = getWordTable();
						// 零组件目录表格
						String[] titles = { "序号", "名称", "图号", "数量", "图位", "备注" };
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
							title.setHeader(true);
//							title.setFixedHeight(20);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table3.addCell(title);
							table3.endHeaders();

						}
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(list.get(
												i).getChinaName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(list.get(
												i).getCounts(), fontChinese2));
										break;
									case 4:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									case 5:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									default:
										break;
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table3.addCell(cell);

								}
							}
						}
						document.add(table3);
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_TYGZ)) {
						ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
						Set<Equipment> equipments = new HashSet<Equipment>();

						ProcessAction action = new ProcessAction();
						WorkStepAction action2 = new WorkStepAction();
						CatalogAction action3 = new CatalogAction();
						Catalog catalog1 = action3
								.findCatalogByType(Constants.CATALOGTYPE_GXNR);
						Collection<ProcessEntity> prs = action
								.findProcessByTechnology(technology);
						// 全部的工步
						for (ProcessEntity process : prs) {
							Collection<WorkStep> sts = action2
									.findStepByProcess(process);
							for (WorkStep step : sts) {
								steps.add(step);
							}
						}

						// 工步下面的工装
						for (WorkStep step : steps) {
							Collection<Equipment> es = step.getEquipments();
							for (Equipment e : es) {
								if (e.getKind().equals("通用工装")) {
									equipments.add(e);
								}
							}
						}
						ArrayList<Equipment> list = new ArrayList<Equipment>();
						for (Equipment equipment : equipments) {
							list.add(equipment);
						}
						EquipmentSort sort = new EquipmentSort();
						Collections.sort(list, sort);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_TYGZ, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						Table table4 = getWordTable();
						// 通用工装目录表格
						String[] titles = { "序号", "名称", "规格", "备注" };
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
//							title.setFixedHeight(20);
							if (i == 2) {
								title.setColspan(3);
							}
							title.setHeader(true);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table4.addCell(title);
							table4.endHeaders();

						}
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell =new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(list.get(
												i).getName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph(list.get(
												i).getSpec(), fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(list.get(
												i).getRemark(), fontChinese2));
										break;
									default:
										break;
									}
									if (j == 2) {
										cell.setColspan(3);
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table4.addCell(cell);
								}
							}
						}
						document.add(table4);
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_ZYGZ)) {
						ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
						Set<Equipment> equipments = new HashSet<Equipment>();

						ProcessAction action = new ProcessAction();
						WorkStepAction action2 = new WorkStepAction();
						CatalogAction action3 = new CatalogAction();
						Catalog catalog1 = action3
								.findCatalogByType(Constants.CATALOGTYPE_GXNR);
						Collection<ProcessEntity> prs = action
								.findProcessByTechnology(technology);
						// 全部的工步
						for (ProcessEntity process : prs) {
							Collection<WorkStep> sts = action2
									.findStepByProcess(process);
							for (WorkStep step : sts) {
								steps.add(step);
							}
						}

						// 工步下面的工装
						for (WorkStep step : steps) {
							Collection<Equipment> es = step.getEquipments();
							for (Equipment e : es) {
								if (e.getKind().equals("专用工装")) {
									equipments.add(e);
								}
							}
						}
						ArrayList<Equipment> list = new ArrayList<Equipment>();
						for (Equipment equipment : equipments) {
							list.add(equipment);
						}
						EquipmentSort sort = new EquipmentSort();
						Collections.sort(list, sort);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_ZYGZ, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						Table table5 = getWordTable();
						// 通用工装目录表格
						String[] titles = { "序号", "名称", "图号、型号、规格", "备注" };
						for (int i = 0; i < titles.length; i++) {
							Cell title =new Cell (new Paragraph(titles[i],
									fontChinese2));
//							title.setFixedHeight(20);
							if (i == 2) {
								title.setColspan(3);
							}
							title.setHeader(true);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table5.addCell(title);
							table5.endHeaders();
						}
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(list.get(
												i).getName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph(list.get(
												i).getSpec(), fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(list.get(
												i).getRemark(), fontChinese2));
										break;
									default:
										break;
									}
									if (j == 2) {
										cell.setColspan(3);
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table5.addCell(cell);
								}
							}
						}
						document.add(table5);
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_SB)) {
						ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
						Set<Device> equipments = new HashSet<Device>();

						ProcessAction action = new ProcessAction();
						WorkStepAction action2 = new WorkStepAction();
						CatalogAction action3 = new CatalogAction();
						Catalog catalog1 = action3.findCatalogByType(Constants.CATALOGTYPE_GXNR);
						Collection<ProcessEntity> prs = action
								.findProcessByTechnology(technology);
						// 全部的工步
						for (ProcessEntity process : prs) {
							Collection<WorkStep> sts = action2
									.findStepByProcess(process);
							for (WorkStep step : sts) {
								steps.add(step);
							}
						}

						// 工步下面的工装
						for (WorkStep step : steps) {
							Collection<Device> es = step.getDevices();
//							for (Equipment e : es) {
////								if (e.getKind().equals("设备")) {
////									equipments.add(e);
////								}
//							}
							equipments.addAll(es);
						}
						ArrayList<Device> list = new ArrayList<Device>();
						for (Device equipment : equipments) {
							list.add(equipment);
						}
						DeviceSort sort = new DeviceSort();
						Collections.sort(list, sort);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_SB, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						Table table6 = getWordTable();
						//设备目录表格
						String[] titles = { "序号", "名称", "图号、型号、规格", "备注" };
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
//							title.setFixedHeight(20);
							if (i == 2) {
								title.setColspan(3);
							}
							title.setHeader(true);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table6.addCell(title);
							table6.endHeaders();
						}
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(list.get(
												i).getName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph(list.get(
												i).getSpec(), fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(list.get(
												i).getRemark(), fontChinese2));
										break;
									default:
										break;
									}
									if (j == 2) {
										cell.setColspan(3);
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table6.addCell(cell);
								}
							}
						}
						document.add(table6);
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_BZYJ)) {
						Set<EnsipBom> sets = technology.getEnsipBoms();
						List<EnsipBom> list = new ArrayList<EnsipBom>();
						for (EnsipBom ensipBom : sets) {
							if("1".equals(ensipBom.getIsStandard())){
								list.add(ensipBom);
							}
						}
						PartSort sort = new PartSort();
						Collections.sort(list, sort);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_BZYJ, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						Table table3 = getWordTable();
						// 零组件目录表格
						String[] titles = { "序号", "名称", "图号", "数量", "图位", "备注" };
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
							title.setHeader(true);
//							title.setFixedHeight(20);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table3.addCell(title);
							table3.endHeaders();

						}
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(list.get(
												i).getChinaName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(list.get(
												i).getCounts(), fontChinese2));
										break;
									case 4:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									case 5:
										cell = new Cell(new Paragraph("" ,
												fontChinese2));
										break;
									default:
										break;
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table3.addCell(cell);

								}
							}
						}
						document.add(table3);
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_FC)) {
						ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
						Set<SubMaterial> subs = new HashSet<SubMaterial>();
						ProcessAction action = new ProcessAction();
						WorkStepAction action2 = new WorkStepAction();
						CatalogAction action3 = new CatalogAction();
						Catalog catalog1 = action3
								.findCatalogByType(Constants.CATALOGTYPE_GXNR);
						Collection<ProcessEntity> prs = action
								.findProcessByTechnology(technology);
						// 全部的工步
						for (ProcessEntity process : prs) {
							Collection<WorkStep> sts = action2
									.findStepByProcess(process);
							for (WorkStep step : sts) {
								steps.add(step);
							}
						}
						// 工步下面全部的辅材
						for (WorkStep step : steps) {
							Collection<SubMaterial> subMaterials = step
									.getMaterials();
							for (SubMaterial s : subMaterials) {
								subs.add(s);
							}
						}
						ArrayList<SubMaterial> list = new ArrayList<SubMaterial>();
						for (SubMaterial subMaterial : subs) {
							list.add(subMaterial);
						}
						SubMaterialSort sort = new SubMaterialSort();
						Collections.sort(list, sort);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_FC, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						Table table7 = getWordTable();
						// 辅助材料目录表格
						String[] titles = { "序号", "名称", "规格", "备注" };
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
//							title.setFixedHeight(20);
							if (i == 2) {
								title.setColspan(3);
							}
							title.setHeader(true);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table7.addCell(title);
							table7.endHeaders();

						}
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(list.get(
												i).getName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph(list.get(
												i).getParameter(), fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(list.get(
												i).getRemark(), fontChinese2));
										break;
									default:
										break;
									}
									if (j == 2) {
										cell.setColspan(3);
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table7.addCell(cell);

								}
							}
						}
						document.add(table7);
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_GZK)) {
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_GZK, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						
						
						ProcessAction action = new ProcessAction();
						StoppageAndProcessStructureAction action2 = new StoppageAndProcessStructureAction();
//						CatalogAction action3 = new CatalogAction();
						ArrayList<Stoppage> stoppages = new ArrayList<Stoppage>();
//						Catalog catalog1 = action3.findCatalogByType(Constants.CATALOGTYPE_GXNR);
						Collection<ProcessEntity> prs = action.findProcessByTechnology(technology);
						// 全部的故障
						for (ProcessEntity process : prs) {
							Collection<StoppageAndProcessStructure> list = action2.findStoppageAndProcessByProcess(process);
							//工序下的故障
							for (StoppageAndProcessStructure stoppageAndProcessStructure : list) {
								stoppages.add(stoppageAndProcessStructure.getStoppage());
							}
							WorkStepAction waction = new WorkStepAction();
							Collection<WorkStep> steps = waction.findStepByProcess(process);
							//工步下的故障
							for (WorkStep workStep : steps) {
								Collection<StoppageAndProcessStructure> list2 = action2.findStoppageAndProcessByProcess(workStep);
								for (StoppageAndProcessStructure stoppageAndProcessStructure : list2) {
									stoppages.add(stoppageAndProcessStructure.getStoppage());
								}
							}
							
						}
						Table table7 =null;
						// 辅助材料目录表格
						String[] titles = { "序号", "故障名称", "故障内容" };
						table7 = new Table(titles.length);
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
//							title.setFixedHeight(20);
							title.setHeader(true);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table7.addCell(title);
							table7.endHeaders();

						}
						if (stoppages != null&&stoppages.size()!=0) {
							for (int i = 0; i < stoppages.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(stoppages.get(
												i).getName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph(stoppages.get(
												i).getDescribe(), fontChinese2));
										break;
									default:
										break;
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table7.addCell(cell);

								}
							}
						}
						document.add(table7);
					} else if (catalog.toString().equals(Constants.CATALOGTYPE_JT)) {
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_JT, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						
						ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
						Set<Diagram> diagrams = new HashSet<Diagram>();
						ProcessAction action = new ProcessAction();
						WorkStepAction action2 = new WorkStepAction();
						CatalogAction action3 = new CatalogAction();
						Catalog catalog1 = action3
								.findCatalogByType(Constants.CATALOGTYPE_GXNR);
						Collection<ProcessEntity> prs = action
								.findProcessByTechnology(technology);
						// 全部的工步
						for (ProcessEntity process : prs) {
							Collection<WorkStep> sts = action2
									.findStepByProcess(process);
							for (WorkStep step : sts) {
								steps.add(step);
							}
						}
						// 工步下面全部的简图
						for (WorkStep workStep : steps) {
							Collection<Diagram> ds = workStep.getDiagrams();
							for (Diagram diagram : ds) {
								diagrams.add(diagram);
							}
						}
//						ArrayList<Diagram> list = new ArrayList<Diagram>();
//						for (Diagram diagram : diagrams) {
//							list.add(diagram);
//						}
						ArrayList<Diagram> list = new ArrayList<Diagram>();
						//去重
						for (Diagram diagram : diagrams) {
							boolean isExist = false;
							for (Diagram d : list) {
								if(d.getId().equals(diagram.getId())){
									isExist = true;
								}
							}
							if(!isExist){
								list.add(diagram);
							}
						}
						DiagramAction action4 = new DiagramAction();
						PnlEamoisBrowser pnl = new PnlEamoisBrowser();
						int total =1;
						for (Diagram e : diagrams) {
							List<Image> images = new ArrayList<Image>();
							String code = e.getCdocumentid();
//							String var = e.getCdocumentver();
//							DocumentView doc = action4.getDiagramByIdAndVer(id, var);
							//根据简图编码、查询出该简图下所属的多张简图
							String sql = "SELECT DOCUMENTID,DOCUMENTNAME,FORMAT FROM DOC_JT WHERE BELONGCODE='"
									+ code + "'";
							ArrayList altResult = SqlMix.getInstance()
									.executeQuery(sql);
							if (altResult != null && altResult.size() != 0)
								for (int i = 0; i < altResult.size(); i++) {
									String str[] = (String[]) altResult.get(i);
									String picCode = str[0];
									ViewDocument viewDoc = action4.getDocumentByIdAndVer2(picCode,
											code, "0");
									String filePath = pnl.getDocFromFtp2(viewDoc);
									Image image = Image.getInstance(filePath);
									images.add(image);
								}
							if (images != null && images.size() > 0) {
								int i =1;
								for (Image img : images) {
									document.add(img);
									Paragraph desc = new Paragraph("图"+total+"."+i);
									desc.setFont(fontChinese2);
//									desc.setSpacingBefore(5);
//									desc.setFirstLineIndent(20);
									document.add(desc);
									i++;
								}
							}
							total++;
						}
						
					}else if(catalog.toString().equals(Constants.CATALOGTYPE_FJ)){
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_FJ, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						
						Table tableVideo = getWordTable();
						// 附件
						String[] titles = { "序号", "文档编码", "文档名称", "文档格式" };
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
//							title.setFixedHeight(20);
							if (i == 2) {
								title.setColspan(3);
							}
							title.setHeader(true);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							tableVideo.addCell(title);
							tableVideo.endHeaders();

						}
						ProcessAction action = new ProcessAction();
						Collection<ProcessEntity> prs = action.findProcessByTechnology(technology);
						ArrayList<String> codes = new ArrayList<String>();
						WorkStepAction action2 = new WorkStepAction();
						//全部的工步
						for (ProcessEntity process : prs) {
							codes.add(process.getCode());
							Collection<WorkStep> sts = action2.findStepByProcess(process);
							for (WorkStep step : sts) {
								codes.add(step.getCode());
							}
						}
//						String sql = "select CDOCUMENTID,CDOCUMENTNAME,CDMODIFYTIME from DOC_008 where "
//								+ "CDOCUMENTID in(select CDOCUMENTID from SYS_065 where code ='"
//								+ technology.getCode() + "')";
//						ArrayList list = SqlMix.getInstance().executeQuery(sql);
						ArrayList list = new ArrayList();
						for (String code : codes) {
							String sql ="SELECT DOCUMENTID,DOCUMENTNAME,FORMAT FROM DOC_FJ WHERE BELONGCODE='"+code+"'";
							ArrayList altResult = SqlMix.getInstance().executeQuery(sql);
							list.addAll(altResult);
						}
						if (list != null&&list.size()!=0) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									String[] str = (String[])list.get(i);
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(str[0], fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph(str[1], fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(str[2], fontChinese2));
										break;
									default:
										break;
									}
									if (j == 2) {
										cell.setColspan(3);
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									tableVideo.addCell(cell);
								}
							}
						}
						document.add(tableVideo);
					}else if(catalog.toString().equals(Constants.CATALOGTYPE_JLQJ)){
						ArrayList<WorkStep> steps = new ArrayList<WorkStep>();
						Set<Instrument> subs = new HashSet<Instrument>();
						ProcessAction action = new ProcessAction();
						WorkStepAction action2 = new WorkStepAction();
						CatalogAction action3 = new CatalogAction();
						Catalog catalog1 = action3
								.findCatalogByType(Constants.CATALOGTYPE_GXNR);
						Collection<ProcessEntity> prs = action
								.findProcessByTechnology(technology);
						// 全部的工步
						for (ProcessEntity process : prs) {
							Collection<WorkStep> sts = action2
									.findStepByProcess(process);
							for (WorkStep step : sts) {
								steps.add(step);
							}
						}
						// 工步下面全部的计量器具
						for (WorkStep step : steps) {
							Collection<Instrument> instruments = step
									.getInstruments();
							for (Instrument s : instruments) {
								subs.add(s);
							}
						}
						ArrayList<Instrument> list = new ArrayList<Instrument>();
						for (Instrument instru : subs) {
							list.add(instru);
						}
						InstrumentSort sort = new InstrumentSort();
						Collections.sort(list, sort);
						// 标题
						Paragraph cell_title = new Paragraph(index2
								+ "、" + Constants.CATALOGTYPE_JLQJ, fontChinese2);
						cell_title.setFont(fontChinese2);
//						cell_title.setSpacingBefore(5);
						cell_title.setFirstLineIndent(20);
						document.add(cell_title);
						Table table7 = getWordTable();
						// 计量器具目录表格
						String[] titles = { "序号", "名称", "规格", "备注" };
						for (int i = 0; i < titles.length; i++) {
							Cell title = new Cell(new Paragraph(titles[i],
									fontChinese2));
//							title.setFixedHeight(20);
							if (i == 2) {
								title.setColspan(3);
							}
							title.setHeader(true);
							title.setHorizontalAlignment(Element.ALIGN_CENTER);// 设置内容居中
							title.setVerticalAlignment(Element.ALIGN_MIDDLE);
							table7.addCell(title);
							table7.endHeaders();

						}
						if (list != null) {
							for (int i = 0; i < list.size(); i++) {
								for (int j = 0; j < titles.length; j++) {
									Cell cell = new Cell();
									switch (j) {
									case 0:
										cell = new Cell(new Paragraph((i + 1)
												+ "", fontChinese2));
										break;
									case 1:
										cell = new Cell(new Paragraph(list.get(
												i).getName(), fontChinese2));
										break;
									case 2:
										cell = new Cell(new Paragraph(list.get(
												i).getSpec(), fontChinese2));
										break;
									case 3:
										cell = new Cell(new Paragraph(list.get(
												i).getRemark(), fontChinese2));
										break;
									default:
										break;
									}
									if (j == 2) {
										cell.setColspan(3);
									}
									cell.setHorizontalAlignment(Element.ALIGN_CENTER);
									cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
//									cell.setFixedHeight(20);
									table7.addCell(cell);
								}
							}
						}
						document.add(table7);
					}
					index2++;
				}
				document.add(new Paragraph());
//				String id  = Message.getLoginuserid();
				String name  = Message.getLoginusername();
				
				String sql = "SELECT MARKBODY,MARKTYPE FROM SIGNATURE WHERE MARKNAME='"+name+"'";
				PreparedStatement pstmt = OpenConnection().prepareStatement(sql);
				ResultSet rs = pstmt.executeQuery();
				String localPath ="";
				if(rs.next()){
					InputStream ins = rs.getBinaryStream("MARKBODY");
					//图片格式
					String format = rs.getString("MARKTYPE");
					//临时图片存放位置
					localPath = "C:/SIGNATURE"+format;
					OutputStream out = new FileOutputStream(localPath);
					
					int tmpi = 0;
					while ((tmpi = ins.read()) != -1) {
						out.write(tmpi);
					}
					ins.close();
					out.flush();
					out.close();
				}
				if(!"".equals(localPath)){
					Image img = Image.getInstance(localPath);
					img.setAlignment(2);
					document.add(img);
					//删除临时图片
					File f = new File(localPath);
					f.delete();
				}
			}
			
			
			// 关闭文档
			document.close();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			if (connection != null) {
				try {
					connection.close();
				} catch (Exception ex) {
					ex.printStackTrace();
				}
			}
			connection = null;
		}
		// 用Windows集成方式打开
		Browse browsefile = new Browse(Browse.BROWSEDOC_RETURN);
		browsefile.browseFile(path);

	}

	public static PdfPTable getTable() {
		try {
			// float[] widths = { 4f, 260, 10f, 260, 10f, 260f, 4f };
			float[] widths = { 50, 80, 200, 50, 50, 200 };

			// new 一个6列的table
			PdfPTable table = new PdfPTable(6);
			// 设置table每一列的宽度，widths里写的是百分比，他们加和需要是1
			table.setWidths(widths);
			// 设置表格在页面上的宽度，设成100表示可以表格填满页面，但是要去掉页面margin
			table.setWidthPercentage(100);
			// 设置表格上端的空白距离，类似css中的margin-top:xxpx;这样在给表格加上标题后，标题就不会跟表格重叠在一起了。
			table.setSpacingBefore(3f);
			table.getDefaultCell().setBorder(0);// 设置表格默认为无边框
			return table;

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}
	public static Table getWordTable() {
		try {
			// float[] widths = { 4f, 260, 10f, 260, 10f, 260f, 4f };
			float[] widths = { 50, 80, 200, 50, 50, 200 };

			Table table = new Table(6);
			table.setWidths(widths);//设置每列所占比例
			table.setWidth(100); // 占页面宽度 
			table.setAlignment(Element.ALIGN_CENTER);//居中显示
			table.setAlignment(Element.ALIGN_MIDDLE);//纵向居中显示
			table.setAutoFillEmptyCells(true); //自动填满
			table.setBorderWidth(1); //边框宽度
//			table.setBorderColor(new Color(0, 125, 255)); //边框颜色
			table.setPadding(0);//衬距，看效果就知道什么意思了
			table.setSpacing(0);//即单元格之间的间距
			table.setBorder(2);//边框
			return table;

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 判断该单元格下方所存在的单元格是否是拆分的、如果是拆分成了多少列,没拆分就返回0
	 * @param polygon
	 * @param polygons
	 * @return
	 */
	public static int handlePolygon(MeaPolygon polygon,Collection<MeaPolygon> polygons){
		int num = 0;
		for (MeaPolygon p : polygons) {
			if(polygon.getY()+polygon.getHeight()==p.getY()){
				if(p.getX()>=polygon.getX()&&p.getX()<polygon.getX()+polygon.getWidth()){
					num++;
				}
			}
		}
		return num;
		
	}
	public static Connection OpenConnection() {
		ResourceBundle pro = ResourceBundle.getBundle("connjg");
		String cIP = pro.getString("CONNJGIP");
		String DATABASENAME = pro.getString("DATABASENAME");
		String USERNAEM = pro.getString("USERNAEM");
		String PASSWORD = pro.getString("PASSWORD");
		try {
			Class.forName("net.sourceforge.jtds.jdbc.Driver");
			connection = DriverManager.getConnection("jdbc:jtds:sqlserver://"
					+ cIP + ":1433;databasename=" + DATABASENAME + "",
					USERNAEM, PASSWORD);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return connection;
	}
	
	
}
